package org.vaadinetherealintegration.client.example5;

import org.vaadinetherealintegration.client.ExampleInterface;

import etrl.core.Geode;
import etrl.core.Group;
import etrl.core.LightStore;
import etrl.core.Lights;
import etrl.core.Node;
import etrl.core.Transform;
import etrl.core.Viewer;
import etrl.resources.Resources;
import etrl.vecmath.Quat4f;
import etrl.vecmath.Vector3f;

public class Example5 implements ExampleInterface
{
		String stone_wall = "VAADIN/widgetsets/org.vaadinetherealintegration.MyWidgetSet/stone_wall.bmp";
        String mousse = "VAADIN/widgetsets/org.vaadinetherealintegration.MyWidgetSet/mousse.png";
		
        /**
         * The viewer...
         */
        private Viewer _viewer;
       
        public Example5(Viewer viewer)
        {
                _viewer = viewer;
        }
       
        public Node buildSceneRoot()
        {
                Transform cubeTransform = new Transform();
                cubeTransform.setPosition(new Vector3f(0.f, 0.f, -10.f));
                cubeTransform.setUniformScale(5.f);
                cubeTransform.setNodeCallback(new RotationCallback(cubeTransform));
                cubeTransform.addTexture(stone_wall, 5.f, 5.f);
                cubeTransform.addTexture(mousse, 1.f, 1.f);
       
                Geode cubeGeode = new Geode();
                cubeGeode.addDrawable(new Sphere());
                cubeTransform.addChild(cubeGeode);
               
                Group root = new Group();
                root.addChild(cubeTransform);
               
                LightStore.getInstance().createLight("light0");
                LightStore.getInstance().setLightPositionDirection("light0", new Vector3f(0.f, 20.f, 0.f));
               
                Lights lights = new Lights();
                lights.addLight("light0");
                lights.addChild(root);
               
                return lights;
        }

        public Vector3f getInitialCameraPos()
        {
                return new Vector3f(0.f, 0.f, 0.f);
        }

        public Quat4f getInitialCameraOrientation()
        {
                return new Quat4f(0.f, 0.f, 0.f, 1.f);
        }

        public void atExit()
        {
                // clear example resources
                _viewer.unloadResources();
        }

        public void atStart()
        {
                // Load example texture resources
                Resources.instance().addTextureToLoad(stone_wall, true);
                Resources.instance().addTextureToLoad(mousse, true);
                _viewer.loadResources();
        }

}

